<template>
  <treeContentLayout>
    <template #tree>
      <LeftTree ref="leftTree" @select="onTreeSelect" @root-tree-data="onRootTreeData" />
    </template>
    <template #content>
      <div :class="[`${prefixCls}`]">
        <a-tabs v-show="departData" defaultActiveKey="base-info">
          <a-tab-pane tab="基本信息" key="base-info" forceRender>
            <FormTab :data="departData" :rootTreeData @success="onSuccess" />
          </a-tab-pane>
        </a-tabs>
        <div v-show="!departData" style="padding-top: 40px">
          <a-empty description="尚未选择部门" />
        </div>
      </div>
    </template>
  </treeContentLayout>
</template>

<script lang="ts" setup name="tree-form">
  import { ref } from 'vue';
  import { useDesign } from '/@/hooks/web/useDesign';
  import LeftTree from './components/leftTree.vue';
  import FormTab from './components/formTab.vue';
  import treeContentLayout from '/@/components/TreeContentLayout/index.vue';

  const { prefixCls } = useDesign('depart-manage');

  // 给子组件定义一个ref变量
  const leftTree = ref();

  // 当前选中的部门信息
  const departData = ref({});
  const rootTreeData = ref<any[]>([]);

  // 左侧树选择后触发
  function onTreeSelect(data: any) {
    departData.value = data;
  }

  // 左侧树rootTreeData触发
  function onRootTreeData(data: any) {
    rootTreeData.value = data;
  }

  function onSuccess() {
    leftTree.value.loadRootTreeData();
  }
</script>

<style lang="less">
  @prefix-cls: ~'@{namespace}-depart-manage';
  .@{prefix-cls} {
    background: @component-background;
    height: 100%;
    padding: 16px;
    .ant-tabs {
      height: 100%;
      .ant-tabs-content {
        height: 100%;
        .ant-spin-nested-loading {
          height: 100%;
          .ant-spin-container {
            height: 100%;
            .ant-form {
              height: calc(100% - 48px);
              overflow: auto;
            }
          }
        }
      }
    }
  }
</style>
